package top.layne.cloud.tsf.consumer.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.tsf.faulttolerance.annotation.TsfFaultTolerance;
import org.springframework.cloud.tsf.faulttolerance.model.TsfFaultToleranceStragety;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import top.layne.cloud.tsf.consumer.service.EchoService;

/**
 * @author : layne
 * @Date: 2020/7/24
 * @Time: 15:02
 * Description:
 */
@RestController
public class EchoController {
    private static final Logger LOGGER = LoggerFactory.getLogger(EchoController.class);

    @Autowired
    private EchoService echoService;

    @Autowired
    private RestTemplate restTemplate;


    @GetMapping("/echo-feign/{message}")
    public String feign(@PathVariable("message") String message) {
        LOGGER.info(">>>>>echo-feign :{}", message);
        return echoService.echo(message);
    }

    @GetMapping("/echo-rest/{message}")
    public String rest(@PathVariable("message") String message) {
        LOGGER.info(">>>>>echo-rest :{}", message);
        return restTemplate.getForObject("http://layne-cloud-tsf-provider/echo/" + message, String.class);
    }


}
